The present invention relates generally to data processing systems and, more particularly, to integrating both modifications to an object model and modifications to a database into source code by an object-relational mapping tool.
Object-relational mapping tools have been created to facilitate development of application programs that utilize a relational database. A relational database stores data in tables having rows (records) and columns (fields). The tables are usually interrelated, and thus, there is a logical structure imposed on the database. This logical structure is known as a schema. Each table may have a primary key, comprising one or more columns that uniquely identify a row. For example, in a table with rows of customers, a column storing each customer""s social security number may be used as the primary key because it uniquely identifies each customer in the table. A table may also have one or more foreign keys, associating a row in one table to one or more rows in another table. For example, where one table contains customer information and another table contains order information for the customers, a foreign key may exist in the order table to relate one customer (or row) in the customer table with one or more orders (or rows) in the order table.
Object-relational mapping tools read database schema information and automatically generate source code from the database. This source code contains a number of classes whose interrelationships reflect the logical structure, or schema, of the database. A class, such as a Java(trademark) class, is a data structure containing both data members that store data and function members (or methods) that act upon the data. The source code may contain one class for each table in the database, and each class may have a data member for each column in the corresponding table. Additionally, the classes contain function members that are used to both get and set the values for the data members and, eventually, update the database.
By using an object-relational mapping tool, a programmer can automatically generate source code to facilitate their database application development. After the source code is generated, the programmer writes code to interact with only the classes in the source code and not the database, thus hiding the complexities of interacting with the database from the programmer. This allows a programmer who is familiar with object-oriented programming to code against familiar classes and not unfamiliar, sometimes cumbersome to use, database query languages.
Although beneficial to programmers, conventional object-relational mapping tools suffer from a limitation. When a programmer runs the object-relational mapping tool, it generates source code with classes that reflect the structure of the database at that time. However, during the lifetime of the database, it is common for a database administrator to change the schema of the database (e.g., add a new field or table). Likewise, it is common for the programmer to update the classes in the source code (e.g., change a field name or delete a field). As such, both the classes and the database tend to evolve and change over time. Conventional object-relational mapping tools, however, are of little help in such situations. These tools can only remap the database to generate classes that contain the database modifications, but which do not contain the programmer""s modifications. Therefore, the programmer""s changes are lost and must be manually recreated, thus wasting significant development time. It is therefore desirable to improve object-relational mapping tools.